QuickOPC User's Guide and Reference
Obtaining Information (OPC UA Alarms & Conditions)
Development Models > Imperative Programming Model > Imperative Programming Model for OPC UA Alarms & Conditions > Obtaining Information (OPC UA Alarms & Conditions)

For obtaining information related to Alarms & Conditions (such as the state of conditions), OPC UA does not introduce any new mechanism over what we have already described for OPC Data (in OPC UA). Please refer to the “Obtaining Information” under “Imperative Programming Model for OPC Data (Class and UA)” for all necessary information.

Methods (and extension methods) such as EasyUAClient.Read, ReadMultiple, ReadValue, ReadMultipleValues can be used.

 

// This example shows how to read a Low state of a limit alarm. Note that you should not normally read a state of an alarm
// from inside its event notification, because the state might have already changed. Instead, include the information you
// need in the Select clauses when subscribing for the event.

using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.AddressSpace;
using OpcLabs.EasyOpc.UA.Navigation;

namespace UADocExamples.AlarmsAndConditions
{
    class ReadAlarmState
    {
        public static void Main1()
        {
            UAEndpointDescriptor endpointDescriptor =
                "opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer";

            UANodeDescriptor alarmNodeDescriptor = new UANodeId(
                namespaceUriString:"http://opcfoundation.org/Quickstarts/AlarmCondition", 
                identifier:"1:Colours/EastTank?Yellow");

            // Knowing the alarm node, and the fact that is an instance of NonExclusiveLevelAlarmType (or its subtype),
            // determine what is its LowState/Id node.
            UANodeDescriptor lowStateIdNodeDescriptor = new UABrowsePath(alarmNodeDescriptor,
                new []
                {
                    UABrowsePathElement.CreateSimple("ns=0;s=LowState"),
                    UABrowsePathElement.CreateSimple("ns=0;s=Id")
                });

            // Instantiate the client object.
            var client = new EasyUAClient();

            Console.WriteLine("Reading alarm state...");
            var lowStateId = (bool)client.ReadValue(endpointDescriptor, lowStateIdNodeDescriptor);

            Console.WriteLine($"Id of LowState: {lowStateId}");
        }
    }
}
# This example shows how to read a Low state of a limit alarm. Note that you should not normally read a state of an alarm
# from inside its event notification, because the state might have already changed. Instead, include the information you
# need in the Select clauses when subscribing for the event.

# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc
import time

# Import .NET namespaces.
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.AddressSpace.Standard import *
from OpcLabs.EasyOpc.UA.AlarmsAndConditions import *
from OpcLabs.EasyOpc.UA.OperationModel import *


def eventNotification(sender, eventArgs):
    print()
    # Display the event.
    if eventArgs.EventData is None:
        print(eventArgs)
        return
    baseEventObject = eventArgs.EventData.BaseEvent
    print('Source name: ', baseEventObject.SourceName, sep='')
    print('Message: ', baseEventObject.Message, sep='')
    print('Severity: ', baseEventObject.Severity, sep='')


# Define which server we will work with.
endpointDescriptor = UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer')

# Instantiate the client object and hook events.
client = EasyUAClient()
client.EventNotification += eventNotification

print('Subscribing...')
IEasyUAClientExtension.SubscribeEvent(
    client,
    endpointDescriptor,
    UANodeDescriptor(UAObjectIds.Server),
    1000)

print('Processing event notifications for 30 seconds...')
time.sleep(30)

print('Unsubscribing...')
client.UnsubscribeAllMonitoredItems()

print('Waiting for 5 seconds...')
time.sleep(5)

print('Finished.')

 

 

See Also